# Maintainer: kpcyrd <kpcyrd[at]archlinux[dot]org>
# Contributor: Knut Ahlers <knut at ahlers dot me>

pkgname=yggdrasil
pkgver=0.5.3
pkgrel=1
pkgdesc="An experiment in scalable routing as an encrypted IPv6 overlay network"
arch=('loong64' 'x86_64')
url="https://github.com/yggdrasil-network/yggdrasil-go"
license=('LGPL3')
depends=('glibc')
makedepends=('go')
source=("${pkgname}-${pkgver}.tar.gz::https://github.com/yggdrasil-network/yggdrasil-go/archive/v${pkgver}.tar.gz"
        'yggdrasil.sysusers')
sha256sums=('024fb3714f8ce170ed464a8d1972520fe67b89f8e4d0304ce55db45b7a9ab08f'
            '233f436a5b4ff62f3da66f871ae9b49ed2b4a13572a83f057a07232627c4b3fd')
b2sums=('bced67d7212b9acccbd69b262d72dadbc61445e8d5349f2668efc58445b380f39cc9f53f2f8a35a0b093ea0563c8159648eec4ccbc2865546f6c3237fd8c65b8'
        '3cf5bfb3c09908f841b39f7206bb472e50e60f10d1b87ab6def97a7212e27627f1e795bbaffd964d2d27a80fbbd1a3be63d63c59793ec1967c02f48b8462c08b')

build() {
  cd "${pkgname}-go-${pkgver}"
  for bin in yggdrasil yggdrasilctl; do
    go build \
      -trimpath \
      -buildmode=pie \
      -mod=readonly \
      -modcacherw \
      -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"
-X github.com/yggdrasil-network/yggdrasil-go/src/version.buildName=yggdrasil
-X github.com/yggdrasil-network/yggdrasil-go/src/version.buildVersion=${pkgver}
" \
      "./cmd/${bin}"
  done
}

package() {
  cd "${pkgname}-go-${pkgver}"
  install -Dm755 -t "${pkgdir}/usr/bin" \
    yggdrasil \
    yggdrasilctl

  install -Dm644 -t "${pkgdir}/usr/lib/systemd/system" \
    contrib/systemd/yggdrasil.service \
    contrib/systemd/yggdrasil-default-config.service
  install -Dm644 "${srcdir}/yggdrasil.sysusers" "${pkgdir}/usr/lib/sysusers.d/yggdrasil.conf"

  install -Dm644 LICENSE -t "${pkgdir}/usr/share/licenses/${pkgname}"
}

# vim: ts=2 sw=2 et:
